<?php

namespace App\Http\Controllers\api;

use App\Events\ProductUsersQrcodeEvent;
use App\Events\UsersAmountEvent;
use App\Http\Controllers\Controller;
use App\Models\product\ProductSonModel;
use App\Models\users\UsersModel;
use App\Service\product\ProductApiService;
use App\Service\users\AccountRecordService;
use Illuminate\Support\Facades\Redis;
use lxs\auth\AesSecret;
use lxs\tools\Tools;

class TestController extends Controller
{


    public function test()
    {
        echo 'this is test';
        echo '<br>';


    }


    /**
     * Api获取用户信息
     */
    public function getUserInfo()
    {
        $data = [
            'mobile' => 13761091514,
            'product_title' => '法律咨询巡律',
            'popularize_id' => '2',
        ];
        $url = 'https://retail.ouankj.com/api/users/get_agent_info';
        return $this->apiTest($data, $url);
    }


    /**
     * Api注册用户
     */
    public function register()
    {
        $data = [
            'unique' => 5810000168,
            'mobile' => 13799999999,
            'pro' => 3,
        ];
        $url = 'https://retail.ouankj.com/api/applet/register';
        return $this->apiTest($data, $url);
    }


    /**
     * Api更新订单状态
     */
    public function createOrder()
    {
        $data = [
            'order_sn' => '33333333',
            'mobile' => '13799999999',
            'pro' => 3,
            'order_status' => 2,
            'pay_price' => 300,
            'pay_time' => 1726222471,
            'create_time' => 1726222471,
            'update_time' => 1726222471,
        ];
        $url = 'https://retail.ouankj.com/api/order/update_order_status';
        return $this->apiTest($data, $url);
    }


    /**
     * Api测试
     */
    private function apiTest($data, $url)
    {
        $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('AES-256-CBC'));
        $encrypt = (new AesSecret('059ea34810f154ed5c6af6e374045214', $iv))->encrypt($data);
        $name = '欧安科技';

        $header = [
            'Content-Type: application/json',
            'Authorization:' . $encrypt['data'],
            'name:' . json_encode($name),
            'iv:' . $encrypt['iv'],
        ];
        return Tools::httpRequest($url, [], 'POST', $header);
    }

}
